<?php
declare(ENCODING = 'utf-8');

/*
 * CR_Workspace.php created on 14 avr. 08 
 * Author: Rodrigue Le Gall
 * 
 * This file is inspired by the project Typo3
 *
 * RPortal is an open source web based Content Management System
 * Copyright (C) 2002-2008  Rodrigue Le Gall
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

/**
 * A Workspace
 *
 * @package CR
 */
class CR_Workspace implements phpCR_WorkspaceInterface {

	/**
	 * @var string
	 */
	protected $name;

	/**
	 * @var CR_Session
	 */
	protected $session;

	/**
	 * @var CR_StorageAccess
	 */
	protected $storageAccess;

	/**
	 * Constructs a Workspace object
	 *
	 * @param string $name
	 * @param phpCR_SessionInterface $session
	 * @param phpCR_StorageAccessInterface $storageAccess
	 */
	public function __construct($name, phpCR_SessionInterface $session,CR_StorageAccessInterface $storageAccess) {
		$this->name = (strlen($name) ? $name : 'default');
		$this->session = $session;
		$this->storageAccess = $storageAccess;
	}

	/**
	 * Returns the Session object through which this Workspace object was
	 * acquired.
	 *
	 * @return CR_Session
	 */
	public function getSession() {
		return $this->session;
	}

	/**
	 * Returns the name of the actual persistent workspace represented by
	 * this Workspace object. This is the name used in Repository->login().
	 */
	public function getName() {
		return $this->name;
	}

	/**
	 * Returns the NamespaceRegistry object, which is used to access the
	 * mapping between prefixes and namespaces. In level 2 repositories the
	 * NamespaceRegistry can also be used to change the namespace
	 * mappings.
	 *
	 * @return CR_NamespaceRegistry
	 * @throws phpCR_RepositoryException
	 */
	public function getNamespaceRegistry() {
		return Injector::getObject('phpCR_NamespaceRegistryInterface',$this->storageAccess);
	}
}
